﻿using System.Web;
using Castle.Windsor;

namespace RuTracker.MVC.Core
{
    public static class Container
    {
        private static IContainerAccessor _accessor;
        public static void SetContainerAccessor(IContainerAccessor accessor)
        {
            _accessor = accessor;
        }

        public static IWindsorContainer Current
        {
            get
            {
                if (_accessor != null)
                    return _accessor.Container;

                //resolve container from application
                var containerAccessor = HttpContext.Current.ApplicationInstance as IContainerAccessor;
                if (containerAccessor != null)
                {
                    return containerAccessor.Container;
                }

                return null;
            }
        }
    }
}